//引入mongoose模块
const mongoose = require('mongoose');

//创建文章集合规则
const articleSchema = new mongoose.Schema({
    title: {
        type: String,
        maxlength: 30,
        minlength: 5,
        required: [true, '请输入文章标题']
    },
    //管理员创建文章时就传author，老师创建文章时就传Tauthor
    Tauthor: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User',
        // required: [true, '请传递作者']
    },
    author: {
        type: String,
        // required: [true, '请传递作者']
    },
    publishDate: {
        type: Date,
        default: Date.now
    },
    content: {
        type: String,
    },
    checked: {
        type: Boolean,
        default: false
    }
});

//根据规则创建集合
const Article = mongoose.model('Article', articleSchema);

//导出集合
module.exports = {
    Article: Article
}